package com.dura.test;

import com.dura.test.client.CacheClient;
import com.dura.test.mapper.ClientBusinessMapper;
import com.dura.test.pojo.ClientBusiness;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Map;

/**
 * @version 1.0
 * @Author 振鹏
 * @Date 2025/3/15 18:04
 * @注释
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class ClientBusinessMapperTest {

    @Autowired
    private ClientBusinessMapper mapper;

    @Autowired
    private CacheClient cacheClient;

    /**
     * 客户信息：采用Hash结构
     * key：client_business:apikey
     * value:用户信息的JSON
     * @throws JsonProcessingException
     */
    @Test
    public void findById() throws JsonProcessingException {
        ClientBusiness cb = mapper.findById(1L);
        System.out.println(cb);
        ObjectMapper objectMapper=new ObjectMapper();
        Map map=objectMapper.readValue(objectMapper.writeValueAsString(cb), Map.class);
        cacheClient.hmset("client_business:"+cb.getApikey(),map);

    }


}
